package com.auxgroup.smarthome.snoti.demo;

import com.auxgroup.smarthome.snoti.client.NotiBootrap;
import com.auxgroup.smarthome.snoti.events.DeviceStatusKvEvent;
import com.auxgroup.smarthome.snoti.events.OfflineEvent;
import com.auxgroup.smarthome.snoti.events.OnlineEvent;
import com.gizwits.noti2.client.Events;
import com.gizwits.noti2.client.LoginData;
import com.gizwits.noti2.client.PushEvents;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Author: laiqiuhua.
 * @Date: 2017/9/4 10:14.
 */
public class Demo {
    public static void main(String[] args) throws InterruptedException {

        NotiBootrap notiBootrap = new NotiBootrap();
        LoginData data = new LoginData("031fd83a03d5403a963fb45d33d85a76", "vK94n319RLCfiSTQR7b6pw", "ZLDs4Lx3TkuxescefqUTaA", "client_commerce", Arrays.asList(Events.ONLINE, Events.OFFLINE, Events.STATUS_KV, Events.STATUS_RAW, Events.ATTR_ALERT, Events.ATTR_FAULT));
        LoginData data1 = new LoginData("60c8cbbef8814de2951383f7040aef26", "jnTiAy//QUqyvYnyIbi/hA", "kSjE+Bv7TNaFmgJeXL1AgA", "client_home", Arrays.asList(Events.ONLINE, Events.OFFLINE, Events.STATUS_KV, Events.STATUS_RAW, Events.ATTR_ALERT, Events.ATTR_FAULT));
//        notiBootrap.loginNoti("031fd83a03d5403a963fb45d33d85a76", "vK94n319RLCfiSTQR7b6pw", "ZLDs4Lx3TkuxescefqUTaA", "client", Arrays.asList(Events.ONLINE, Events.OFFLINE, Events.STATUS_KV, Events.STATUS_RAW, Events.ATTR_ALERT, Events.ATTR_FAULT));
        List<LoginData> datas = new ArrayList<>();
        datas.add(data);
        datas.add(data1);
        notiBootrap.loginNoti(datas);
        notiBootrap.registerCallbackEvent(PushEvents.DEVICE_ONLINE, new OnlineEvent());
        notiBootrap.registerCallbackEvent(PushEvents.DEVICE_OFFLINE, new OfflineEvent());
        notiBootrap.registerCallbackEvent(PushEvents.DEVICE_STATUS_KV, new DeviceStatusKvEvent());

        // 发起远程控制
        Map attrs = new HashMap();
        attrs.put("temperature", 9);
        attrs.put("wind_speed_1", 1);

        notiBootrap.sendControlMessage("031fd83a03d5403a963fb45d33d85a76", "34ea34ced1ed", "tN6b3fuWWUfxyRYeie94X5", attrs);
        TimeUnit.SECONDS.sleep(1);
        notiBootrap.sendControlMessage("031fd83a03d5403a963fb45d33d85a76", "34ea34ced1ed", "tN6b3fuWWUfxyRYeie94X5", attrs);

        notiBootrap.receiveMessage();


    }

}
